part of _;

extension on MainPage_Message {
  Widget view_item(int index) {
    final conversation = conversations![index];
    return Slidable(
      key: Key(conversation.conversationID),
      endActionPane: ActionPane(
        extentRatio: 100 / yScreenSize().width,
        motion: ScrollMotion(),
        children: [
          SlidableAction(
            padding: EdgeInsets.zero,
            backgroundColor: Colors.red,
            foregroundColor: Colors.white,
            icon: Icons.delete,
            label: '删除',
            onPressed: (context) {
              YIM.conversationManager.delete(
                conversationType: YIMEnum_ConversationType.P2P,
                conversationID: conversation.conversationID,
                deleteServer: true,
                callback: (isSuccess) {
                  yToast(isSuccess ? "删除成功" : "删除失败");
                },
              );
            },
          ),
        ],
      ),
      child: YButton(
        padding: EdgeInsets.all(10),
        color: Colors.white,
        child: Row(
          children: [
            YImageCircle(50, 50, conversation.avatar),
            YSpacer(width: 10),
            Expanded(
              child: Column(
                children: [
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(child: Text(conversation.name)),
                      YSpacer(width: 10),
                      Text(conversation.date.toString(), style: TextStyle(color: Colors.grey, fontSize: 12)),
                    ],
                  ),
                  YSpacer(height: 5),
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                        child: ExtendedText(
                          conversation.content.fixAutoLines(),
                          strutStyle: StrutStyle(forceStrutHeight: true, height: 1.6),
                          specialTextSpanBuilder: mySpecialTextSpanBuilder,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(color: Colors.grey, fontSize: 12),
                        ),
                      ),
                      YSpacer(width: 10),
                      MyViews.view_badge(conversation.unReadCount),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
        onTap: () => yIntent(ChatPage(serviceName: conversation.name, serviceAvatar: conversation.avatar, serviceID: conversation.conversationID)),
      ),
    );
  }
}
